package com.company.project.core;

import com.alibaba.fastjson.JSON;

/**
 * 统一API响应结果封装
 */
public class Result<T> {
    private int code;
    private String msg;
    private T data;
    /**
     * 分页信息
     */
    private Page page;

    public Result(){

    }

    public Result(ResultCode resultCode){
        this.code = resultCode.code();
        this.msg = resultCode.msg();
    }

    public Result setCode(ResultCode resultCode) {
        this.code = resultCode.code();
        return this;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Page getPage() {
        return page;
    }

    public Result setPage(Page page) {
        this.page = page;
        return this;
    }

    public Result setMessage(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
